package com.wz.common.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * <p>Project: wz_api - CorsConfig
 * <p>Powered by pisces On 2022-01-16 21:35:37
 * <P>Created by IntelliJ IDEA
 *
 * @author ww606851@163.com
 * @version 1.0
 * @description:
 * @since 8
 */

@Configuration
public class CorsConfig {

    @Bean
    public CorsFilter corsFilter() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*");//允许跨域的域名
        corsConfiguration.addAllowedMethod("*"); //允许请求的方法
        corsConfiguration.addAllowedHeader("*");// 允许任何请求头
        corsConfiguration.setMaxAge(3600l);//有效时长
        UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();
        corsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsFilter(corsConfigurationSource);
    }
}
